import { defineStore } from "pinia";
import { ref } from "vue";

export const useStudentStore = defineStore('student',() => {
    const students = ref([])

    const addStudent = (student) => {
        student.id = Date.now()
        student.grades = {
            frontend: null,
            english:null,
            python:null
        }
        students.value.push(student)
    }

    const updateStudentGrades = (id,grades) => {
        const student = students.valuefind((s) => s.id === id)
        if (student) {
            student.grades = grades
        }
    }
    
    const getStudentById = (id) => {
        return students.value.find((s) => s.id === id)
    }

    const getStudentByUsername = (username) => {
        return students.value.find((s) => s.username === username)
    }

    return {students,addStudent,updateStudentGrades,getStudentById,getStudentByUsername}
})